package com.dongdong.bookstore.module.test;

import cn.hutool.core.lang.Console;
import com.dongdong.bookstore.common.api.ResultData;
import com.dongdong.bookstore.common.exception.ApiException;
import com.dongdong.bookstore.data.UserData;
import com.dongdong.bookstore.module.ums.model.Admin;
import com.dongdong.bookstore.module.ums.service.AdminService;
import com.dongdong.bookstore.security.model.CustomUserDetails;
import com.dongdong.bookstore.security.utils.JwtTokenUtil;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

/**
 * @author chiangkai
 * @date 2021-10-14
 * @email chiangkk@163.com
 */
@Slf4j
@RestController("/test")
@Api(tags = "测试")
public class MyController {
    @GetMapping("/t1")
    public String t1() throws Exception {
        if (true) {
            throw new ApiException("这是异常");
        }
        return "hello world";
    }

    @GetMapping("/t2")
    public ResultData<A> t2() {
        return ResultData.result(200, "测试", new A(1, "小明"));
    }


    @GetMapping("/t3")
    public A t3() {
        return new A(1, "小明");
    }

    @GetMapping("/t4")
    public boolean t4() {
        return true;
    }

    @GetMapping("/t5")
    public boolean t5() {
        return false;
    }

    @GetMapping("/t6")
    public String t6() {
        return "t6";
    }


    @Autowired
    private AdminService adminService;

    @GetMapping("/t7")
    public Admin t7() {
        String userName = "admin1";
        return adminService.getAdminByUsername(userName);
    }

    @Value("${redis.key.cms.user}")
    private String REDIS_KEY_USER;

    @RequestMapping("/t8")
    public String t8() {
        return REDIS_KEY_USER;
    }

    @Data
    @AllArgsConstructor
    class A {
        int id;
        String name;
    }
}
